<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //累加
    function fun(n) {
      if (n === 1) {
        return 1;
      } else {
        return n = n + fun(n - 1);
      }
    }
    console.log(fun(4))

    //深拷贝
    const oldobj = {
      name: 'xiaming',
      age: '20',
      colors: ['red', 'blue', 'black'],
      frind: {
        name: 'xiaohong'
      }
    }

    function copy(obj) {
      let newObj = {};

      for (let key in obj) {
        if (obj[key] instanceof Object) {
          newObj[key] = copy(obj[key]);
        } else {
          newObj[key] = obj[key];
        }
      }

      return newObj;
    }
    const newobj = copy(oldobj);

    newobj.frind.name = 'xxx';
    console.log(oldobj)
    console.log(newobj)
  </script>
</body>

</html>